<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/28
 * Time: 19:16
 */

function __autoload($classname)
{
    include "$classname.php";
}
$db=new MyPDO();

//向student表中插入三条测试数据
$res = $db->insert("INSERT INTO T_student (Stud_id,Stud_name,Stud_sex,Birth_date,Entry_date,Mobile,Birth_place,Reserve)
VALUES ('0928001','张三','男','1998-5-4','2016-9-1','15545678911','湖南长沙','这是张三的备注'),
('0928002','李四','男','1997-6-8','2016-9-1','15545789521','湖南邵阳','这是李四的备注'),
('0928003','王花','女','1998-2-5','2016-9-1','15745689928','浙江嘉兴','这是王花的备注')");
var_dump($res);

//向course表中插入三条测试数据
$res1=$db->insert("INSERT INTO T_course (Course_id,Course_name,Teacher_name)
VALUES ('01','PHP','大鹏'),('02','cocos','小朱'),('03','MySql','大鹏');");
var_dump($res1);

//向score表中插入三条测试数据
$res2=$db->insert("INSERT INTO T_score (Score_id,S_course_id,S_stud_id,Score)
VALUES ('316101','01','0928001','92.5'),
('316102','02','0928002','60'),
('316103','03','0928003','85.6')");
var_dump($res2);

//向student表中插入张学友的数据
$res3=$db->insert("INSERT INTO T_student (Stud_id,Stud_name,Stud_sex,Birth_date,Entry_date,Mobile,Birth_place)
VALUES ('2009010001','张学友','男','1980-10-4','2009-9-1','15012345678','湖南长沙')");
var_dump($res3);

//查询籍贯为湖南长沙的学生基本信息
$res4=$db->select("SELECT * FROM T_student WHERE Birth_place = '湖南长沙'");
echo "籍贯为湖南长沙的学生信息:"."<br>";
var_dump($res4);

//查询出姓名为张学友的学生所有课程的成绩
$res5=$db->select("SELECT * FROM T_score  c
INNER JOIN T_student u
ON c.`S_stud_id` = u.`Stud_id`
INNER JOIN T_course a
ON c.`S_course_id`=a.`Course_id`
WHERE Stud_name = '张学友';");
echo "张学友的成绩为:"."<br>";
var_dump($res5);

//查询mysql这门课程的平均成绩
$res6=$db->select("SELECT AVG(Score) FROM T_score  c
INNER JOIN T_student u
ON c.`S_stud_id` = u.`Stud_id`
INNER JOIN T_course a
ON c.`S_course_id`=a.`Course_id`
WHERE Course_name = 'MySql';");
echo "平均成绩为:"."<br>";
var_dump($res6);








